#include <stdio.h>

__int64 leftmost[ 100002 ], rightmost[ 100002 ], max, high[ 100002 ];

int main( )
{
    int n, i, j;
    while ( scanf("%d", &n) != EOF && n )
    {
        max = 0;
        for ( i = 1; i <= n; i++ )
            scanf("%I64d", &high[ i ]);
        high[ 0 ] = high[ n + 1 ] = -1;
        leftmost[ 1 ] = 0;
        rightmost[ n ] = n + 1;
        for ( i = 1; i <= n; i++ )
        {
            j = i;
            leftmost[ i ] = i - 1;
            while ( high[ leftmost[ j ] ] >= high[ i ] )
            {
                j = leftmost[ j ];
                leftmost[ i ] = leftmost[ j ];
            }
        }
        for ( i = n; i >= 1; i-- )
        {
            j = i;
            rightmost[ i ] = i + 1;
            while ( high[ rightmost[ j ] ] >= high[ i ] )
            {
                j = rightmost[ j ];
                rightmost[ i ] = rightmost[ j ];
            }
        }
        for ( i = 1; i <= n; i++ )
            if ( max < ( rightmost[ i ] - leftmost[ i ] - 1 ) * high[ i ] )
                max = ( rightmost[ i ] - leftmost[ i ] - 1 ) * high[ i ];
        printf("%I64d\n", max);
    }
    return 0;
}